<?php
  require_once('functions/config.php');
  function register( $login, $password, $password2, $email ) {
    if( $password == $password2 )
    {
      $login = mysql_real_escape_string( trim( $login ) );
      $password = sha1( mysql_real_escape_string( trim( $password ) ) );
      $check_users = mysql_query( "SELECT * FROM `accounts` WHERE login='$login'" );
      $check_users = mysql_num_rows( $check_users );
      if( $check_users == 0 )
      {
        $insert_user = mysql_query( "INSERT INTO accounts (login, password, email) VALUES('$login', '$password', '$email')" ) or die("Error!");
        echo 'Konto '.$login.' zostalo utworzone';
      }
      else
      {
        echo 'Taki użytkownik juz istnieje.';
      }
    }
    else
    {
      echo 'Podane hasła muszą być identyczne!';
    }
  }
  $mysql_connect = mysql_connect( DB_CORE_ADDRESS, DB_CORE_USERNAME, DB_CORE_PASSWORD );
  $mysql_select_db = mysql_select_db( DB_CORE_DATABASE );
  $mysql_query = mysql_query("SELECT * FROM players WHERE id=1") or die('Błąd zapytania'); 
  if (isset($_POST['konto']) and isset($_POST['password']) and isset($_POST['password2']) and isset($_POST['email']))
  {
    register($_POST['konto'], $_POST['password'], $_POST['password2'], $_POST['email']);
  }
  else
  {
?>
    <h1>Dodaj nowego uzytkownika</h1>
    <form action="register.php" method="post">
      <strong>Nazwa konta:</strong><input name="konto" type="text" value="" /><br>
      <strong>Haslo:</strong><input name="password" type="password" value="" /><br>
      <strong>Powtorz haslo:</strong><input name="password2" type="password" value="" /><br>
      <strong>Email : </strong><input name="email" type="text" value="" /><br />
      <input type="submit" value="Zarejestruj" />
    </form>
<?php
  }
?>
